package com.hspedu.map_;

import java.util.Comparator;
import java.util.TreeMap;

/**
 * @author LiuJinTao
 * @className TreeMap_
 * @date 2024/06/13 22:20
 * @description TODO
 */
@SuppressWarnings({"all"})
public class TreeMap_ {
    public static void main(String[] args) {
        // 使用默认构造器，创建 TreeMap，默认字符串自然排序
//        TreeMap treeMap = new TreeMap();
//        TreeMap treeMap = new TreeMap(new Comparator() {// 默认就是这个
//            @Override
//            public int compare(Object o1, Object o2) {
//                return ((String)o1).compareTo((String)o2);
//            }
//        });
        TreeMap treeMap = new TreeMap(new Comparator() {// 按照K字符串长度从大到小排序
            @Override
            public int compare(Object o1, Object o2) {
                return ((String)o2).length() - ((String)o1).length();
            }
        });
        treeMap.put("jack", "杰克");
        treeMap.put("tom", "汤姆");
        treeMap.put("kristina", "克瑞斯提诺");
        treeMap.put("smith", "史密斯");
        System.out.println("treeMap=" + treeMap);
    }
}
